<?php

namespace app\controller;

use app\model\Card;
use app\model\Fish;
use app\model\Skin;
use app\model\Staff;
use app\model\UserBackpack;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

//背包控制器
class UserBackpackController extends Base
{

    /**
     * 获取用户背包信息
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws DataNotFoundException
     */
    public function list(): Response
    {
        $category = $this->request->get('category');


        $user_backpack_list = (new UserBackpack())->select();
        $res = null;
        foreach ($user_backpack_list as $item) {
            switch ($item->category) {
                case USER_BACKPACK_CATEGORY['消耗品']:
                    $res = (new Staff())->select();
                    break;
                case USER_BACKPACK_CATEGORY['珍贵材料']:
                    $res = (new Card())->select();
                    break;
                case USER_BACKPACK_CATEGORY['加工品']:
                    $res = (new Skin())->select();
                    break;
                case USER_BACKPACK_CATEGORY['其他']:
                    $res = (new Fish())->select();
                    break;
                default:
                    return $this->fail('类型错误');
            }
        }





        return $this->success('ok', $res->toArray());
    }


}